package com.sduept.nwld.dataview.controller.query;

import com.sduept.bigdata.fault.entity.FaultRecord;
import com.sduept.bigdata.web.jsf.controller.AbstractController;
import com.sduept.core.dao.SuperDAO;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import javax.inject.Named;
import javax.faces.bean.RequestScoped;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

@Named
@RequestScoped
public class LineFaultQueryView extends AbstractController {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1305395777463954185L;
	
	private List<FaultRecord> records = new ArrayList<>();
	
	@Autowired
	private SuperDAO dao;
	
	@PostConstruct
	private void init(){
		String selectName = getParameter("selectName");
		if(selectName != null){
			try {
				selectName = URLDecoder.decode(selectName, "utf-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
//			records = dao.findByCondition("equipment='"+selectName+"'", null, new int[]{0,10}, FaultRecord.class);
			records = dao.findByCondition("equipment = ?",  new Object[]{selectName}, null, new int[]{0,10}, FaultRecord.class);
		} else {
//			records = dao.findByCondition(null, null, new int[]{0,10}, FaultRecord.class);
			records = dao.findByCondition(null, null, null, new int[]{0,10}, FaultRecord.class);
		}
	}
	
	private String paramId;
	private String paramName;
	public List<FaultRecord> getRecords() {
		return records;
	}
	public void setRecords(List<FaultRecord> records) {
		this.records = records;
	}
	public String getParamId() {
		return paramId;
	}
	public void setParamId(String paramId) {
		this.paramId = paramId;
	}
	public String getParamName() {
		return paramName;
	}
	public void setParamName(String paramName) {
		this.paramName = paramName;
	}
	
	

}
